

library(tidyverse)


options(mc.cores = parallel::detectCores())
rstan_options(auto_write = TRUE)


manifesto <- read_csv("MPDataset_MPDS2020b.csv") # Load the Manifesto Project database

# Filter the relevant years and parties for the US
manifesto_us_1956_1970 <- manifesto %>%
  filter(countryname == "United States",
         partyname %in% c("Republican Party", "Democratic Party")) %>%
  select(countryname, edate, partyname, pervote, rile) %>%
  mutate(year = year(as.Date(edate, format = "%d/%m/%Y")),
         partyname = factor(partyname, levels = c("Republican Party", "Democratic Party"))) %>%
  filter(year %in% 1956:1970)



figure <-
  manifesto_us_1956_1970 %>%
  ggplot() +
  geom_hline(yintercept = 0) +
  geom_point(aes(year, rile),
             cex = 5) +
  geom_line(aes(year, rile, linetype = partyname),
            size = 2) +
  scale_linetype_manual(values = c("dashed", "solid")) +
  labs(x = "Election Year",
       y = "Right-Left Manifesto Score") +
  scale_x_continuous(breaks = c(1956, 1960, 1964, 1968)) +
  theme_minimal() +
  theme(plot.margin = unit(c(1,1,1,1), "cm"),
        panel.grid.minor = element_blank(),
        axis.title = element_text(size = 30),
        axis.title.x = element_text(size = 30, vjust = -3),
        axis.title.y = element_text(size = 30, vjust = 4),
        axis.text.x = element_text(size = 25, color = "black"),
        axis.text.y = element_text(size = 25, color = "black"),
        legend.text = element_text(size = 25),
        legend.title = element_blank(),
        legend.position = "right",
        legend.key.width = unit(5, "cm"),
        legend.key.size = unit(3, "cm"))

# Save a PNG of the figure
png("figure-6.png",
    height = 20,
    width = 35,
    units = "cm",
    res = 1000)
figure
dev.off()









